"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// app.js
const index_1 = require("./store/index");
const appConfig_1 = require("./config/appConfig");
const tabBar_1 = require("./utils/tabBar");
const originalPage = Page;
Page = function (options) {
    const onLoad = options === null || options === void 0 ? void 0 : options.onLoad;
    const onShow = options === null || options === void 0 ? void 0 : options.onShow;
    return originalPage(Object.assign(Object.assign({}, options), { onLoad(...args) {
            if (this.route) {
                console.log(`load page: ${this.route}.wxml`);
            }
            if (typeof onLoad === "function") {
                onLoad.apply(this, args);
            }
        },
        onShow(...args) {
            if (this.route) {
                console.log(`show page: ${this.route}.wxml`);
            }
            if (typeof onShow === "function") {
                onShow.apply(this, args);
            }
        } }));
};
App({
    onLaunch() {
        if (appConfig_1.appConfig.useCloud) {
            if (!wx.cloud) {
                console.error("请使用 2.20.0 或以上的基础库以使用云能力");
            }
            else {
                wx.cloud.init({
                    env: index_1.globalStore.envId,
                    traceUser: true,
                });
            }
        }
        index_1.globalStore.initAppData().then(() => {
            (0, tabBar_1.applyTabBar)(index_1.globalStore.isChef ? "chef" : index_1.globalStore.isDiner ? "diner" : "guest");
        });
    },
    onPageNotFound(res) {
        console.warn("页面未找到", res);
    },
    onShow(options) {
        console.log("App onShow", options);
        (0, tabBar_1.applyTabBar)(index_1.globalStore.isChef ? "chef" : index_1.globalStore.isDiner ? "diner" : "guest");
    },
    globalStore: index_1.globalStore,
});
